<template>
	<my-bottom-popup
		:show="props.show"
		title="服务地址"
		confirm
		confirmText="选择其他地址"
		@close="onClose"
		@cancel="onClose"
		@confirm="goPage('/pages/my/address-list/address-list')"
	>
		<scroll-view scroll-y class="serve-address">
			<view class="address-list">
				<view class="address-item" v-for="item in addressList" :key="item.id" @click="selectAddress(item.id)">
					<u-icon class="icon" :name="selectedId === item.id ? 'checkbox-mark' : 'map'" :color="selectedId === item.id ? '#3E9DBB' : '#242424'" size="42rpx"></u-icon>
					<view>
						<view class="address">
							<text v-if="item.defaultFlag" class="default-address">默认</text>
							<text>{{ item.province }}{{ item.city }}{{ item.area }}{{ item.street }}{{ item.address }}</text>
						</view>
						<view class="name">{{ item.name }} {{ item.mobile }}</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</my-bottom-popup>
</template>

<script lang="ts" setup>
	import { ref, toRef } from 'vue';
	import { goPage } from '@/utils';
	// import { useStore } from 'vuex';
	import MyBottomPopup from '@/components/my-bottom-popup/my-bottom-popup.vue';
	
	// const store = useStore();
	const emits = defineEmits(['update:show', 'close-address']);
	const props = defineProps({
		show: {
			type: Boolean,
			default: false,
		},
	});
	// 选中地址
	const selectedId = ref<number>(-1);
	const onClose = (): void => {
		emits('update:show');
		emits('close-address', selectedId.value);
	};
	const addressList = ref([]);
	// 选中地址
	const selectAddress = (id: number): void => {
		selectedId.value = id;
		onClose();
	};
	defineExpose({
		selectedId,
	});
</script>

<style lang="scss" scoped>
	.serve-address {
		height: 680rpx;
		.address-list {
			width: 670rpx;
			background: #FFFFFF;
			.address-item {
				padding: 28rpx 0;
				border-bottom: 1rpx solid #eee;
				display: flex;
				align-items: center;
				&:nth-last-child(1) {
					border-bottom: 0;
				}
				.icon {
					margin: 0 25rpx 0 10rpx;
				}
				.address {
					line-height: 36rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #242424;
					margin-bottom: 16rpx;
				}
				.default-address {
					height: 32rpx;
					padding: 0 14rpx;
					background: #EEEEEE;
					border-radius: 16rpx;
					line-height: 32rpx;
					font-size: 20rpx;
					font-weight: 400;
					color: #707070;
					text-align: center;
					display: inline-block;
					margin: 0 8rpx 0 0;
				}
				.name {
					line-height: 24rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #242424;
				}
			}
		}
	}
</style>